using System;
using SystemFrameworks.ExceptionManagers;

namespace SystemFrameworks.UserException
{
	/// <summary>
	/// Summary description for DataCheckException.
	/// </summary>
	public class DataCheckException : BaseApplicationException
	{
		//check department id
		public const int LENGTH_CHECK_DEPARTMENT_ERROR =12;
		//From date must be less than to date
		public const int LENGTH_CHECK_VALID_CHAR_ERROR =11;

		//From date must be less than to date
		public const int LENGTH_CHECK_FROM_TO_DATE_ERROR =10;

		//mail number
		public const int LENGTH_CHECK_MAIL_ERROR =9;
		//Phone number
		public const int LENGTH_CHECK_PHONE_ERROR =8;
		//lenth
		public const int LENGTH_CHECK_SPECIFIED_ERROR =7;

		//invalid letter
		public const int LETTER_ERROR = 6;
		//invalid number
		public const int NUMBER_ERROR = 5;
		//invalid date 
		public const int NUMBER_LETTER_ERROR = 4;
		//invalid date 
		public const int INVALID_DATE = 3;
		//value request check error number
		public const int VALUE_REQUIRED_ERROR  = 2;
		//length check number
		public const int LENGTH_CHECK_ERROR  = 1;
		//check error number
		public const int CHECK_ERROR  = 0;
		
		private int errType_ = CHECK_ERROR;
		private string fieldNm_  = "";   //field name
		private string maxLength_  = "0";
		private string errMsg_  = "";
		private string sMinData_  = "0";
		private string sMaxData_  = "0";

		/// <summary>
		///  construct the class
		/// </summary>
		/// <param name="errMsg"></param>
		public DataCheckException( string errMsg)
		{
			errMsg_=errMsg;
		}
		/// <summary>
		/// construct the class with type property
		/// </summary>
		/// <param name="type"></param>
		public DataCheckException( int type)
		{
			_init(type, fieldNm_, int.Parse( maxLength_));
		}

		/// <summary>
		/// construct the class with the type and fieldNm properties
		/// </summary>
		/// <param name="type"></param>
		/// <param name="fieldNm"></param>
		public DataCheckException( int type,string fieldNm)
		{
			_init(type, fieldNm,int.Parse(maxLength_));
		}
		
		/// <summary>
		/// construct the class with the type and fieldNm properties
		/// </summary>
		/// <param name="type"></param>
		/// <param name="fieldNm"></param>
		public DataCheckException( int type,string fieldNm,int lenth)
		{
			_init(type, fieldNm,lenth);
		}

		/// <summary>
		/// construct the class with the type,fieldNm minimum num and maximum num
		/// </summary>
		/// <param name="type"></param>
		/// <param name="fieldNm"></param>
		/// <param name="sMinData"></param>
		/// <param name="sMaxData"></param>
		public  DataCheckException( int type,string fieldNm,string sMinData,string sMaxData)
		{
			_init( type,  fieldNm,  sMinData, sMaxData);
		}		

		/// <summary>
		///  initialize the properties 
		/// </summary>
		/// <param name="type"></param>
		/// <param name="fieldNm"></param>
		/// <param name="maxLength"></param>
		private void _init(int type, string fieldNm, int maxLength)
		{
			errType_ = type;
			fieldNm_ = fieldNm;
			maxLength_ = maxLength.ToString();
		}

		/// <summary>
		/// initialize the properties with type,field name ,maximum value ,minimum value
		/// </summary>
		/// <param name="type"></param>
		/// <param name="fieldNm"></param>
		/// <param name="sMinData"></param>
		/// <param name="sMaxData"></param>
		private void _init(int type, string fieldNm, string sMinData,string sMaxData)
		{
			errType_ = type;
			fieldNm_ = fieldNm;
			sMinData_ = sMinData;
			sMaxData_=sMaxData;
		}

		public  string  getMessage() 
		{
			string  strMsg="" ;
			switch( errType_)
			{  
				case LENGTH_CHECK_DEPARTMENT_ERROR:
					strMsg= "The field "+fieldNm_ + " must contain the parent id";
					return strMsg;	
				case LENGTH_CHECK_VALID_CHAR_ERROR:
					strMsg= "The field "+fieldNm_ + " must be the valid characters";
					return strMsg;	
				case LENGTH_CHECK_FROM_TO_DATE_ERROR:
					strMsg= "The from date must be less than to date ";
					return strMsg;	
				case LENGTH_CHECK_MAIL_ERROR:
					strMsg= "The field "+fieldNm_ + " is the wrong mail address ";
					return strMsg;
				case LENGTH_CHECK_PHONE_ERROR:
				   strMsg= "The field "+fieldNm_ + " must be number ,(-) characters";
				   return strMsg;
				case LENGTH_CHECK_SPECIFIED_ERROR:
					strMsg= "The field "+fieldNm_ + " is must be the length " + maxLength_ ;
					return strMsg;		
				case LETTER_ERROR:
					strMsg="The field "+fieldNm_ +" must be letters ";
					return strMsg;		
				case NUMBER_ERROR:
					strMsg="The field "+fieldNm_ +" must be numbers";
					return strMsg;	
				case NUMBER_LETTER_ERROR:
					strMsg="The field "+fieldNm_ +" must be letters or numbers";
					return strMsg;	
				case INVALID_DATE:
					strMsg="The field "+fieldNm_ +" is invalid";
					return strMsg;					
				case VALUE_REQUIRED_ERROR:
					strMsg= "The field "+fieldNm_ + " must be input" ;
					return strMsg;					
				case LENGTH_CHECK_ERROR:
					strMsg= "The field "+fieldNm_ + " is beyond the max length " + maxLength_ ;
					return strMsg;					
				case CHECK_ERROR:
					strMsg="Check error ";
					return strMsg;					
				default:
					return strMsg;
			}

		}
	}
}